package kfs.light.screen;

import java.awt.AWTException;
import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Screen {
	private BufferedImage image;
	private List<String> zoneKeys;
	private Map<String, Zone> zoneMap;

	public void getScreenShot() throws HeadlessException, AWTException {
		image = new Robot().createScreenCapture(new Rectangle(Toolkit
				.getDefaultToolkit().getScreenSize()));
	}

	public Map<String, Color> getColourMap() throws InterruptedException {

		if (image != null && zoneKeys != null && zoneMap != null) {
			Map<String, Color> result = new HashMap<String, Color>();
			for (int i = 0; i < zoneKeys.size(); i++) {
				Zone zone = zoneMap.get(zoneKeys.get(i));
				zone.updateImage(image);
				zone.updateColor();
				result.put(zoneKeys.get(i), zone.getColor());
			}
			return result;
		}
		return null;
	}

	public Map<String, Zone> getZoneMap() {
		return zoneMap;
	}

	public void setZoneMap(Map<String, Zone> zoneMap) {
		this.zoneMap = zoneMap;
	}

	public List<String> getZoneKeys() {
		return zoneKeys;
	}

	public void setZoneKeys(List<String> zoneKeys) {
		this.zoneKeys = zoneKeys;
	}

}
